package json;

import java.util.Date;

import net.sf.json.JSONNull;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

import org.apache.commons.lang.time.DateFormatUtils;

public class JsonDateValueProcess implements JsonValueProcessor {
	@Override
	public Object processArrayValue(Object value, JsonConfig jsonconfig) {
		return processValue(value);
	}

	@Override
	public Object processObjectValue(String key, Object value, JsonConfig jsonconfig) {
		return processValue(value);
	}

	private Object processValue(Object value) {
		if (value == null) {
			return JSONNull.getInstance();
		}
		if (value instanceof Date) {
			return DateFormatUtils.format((Date) value, "yyyy-MM-dd HH:mm:ss");
		}
		return value.toString();
	}
}
